-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http2: use aliased buffer for perf stats, add stats #18020
Conversation
doc/api/http2.md
Outdated
* `streamCount` {number} The number of `Http2Stream` instances processed by | ||
the `Http2Session`. | ||
* `receivedBytes` {number} The number of bytes received for this `Http2Session`. | ||
* `sentBytes` {number} The number of bytes sent for this `Http2Session`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The net
& fs
APIs use bytesWritten
and bytesRead
for these values… might be worth being consistent with that?
Edit: Thinking about it, I would have a pretty strong preference for consistency, because that means we might be able to consolidate some of the code around handling C++ streams on the JS side…
lib/internal/http2/util.js
Outdated
enumerable: true, | ||
value: sessionStats[IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS] | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why not use plain writable properties? Is that what we do in the rest of the perf
API, or even spec-mandated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, it's not spec'd to require it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good.
lib/internal/http2/util.js
Outdated
@@ -143,6 +143,8 @@ const { settingsBuffer, optionsBuffer } = binding; | |||
// Node.js core as a performance optimization. | |||
const { sessionState, streamState } = binding; | |||
|
|||
const { sessionStats, streamStats } = binding; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be merged with the line before.
lib/perf_hooks.js
Outdated
@@ -467,6 +469,10 @@ function doNotify() { | |||
// Set up the callback used to receive PerformanceObserver notifications | |||
function observersCallback(entry) { | |||
const type = mapTypes(entry.entryType); | |||
|
|||
if (type === NODE_PERFORMANCE_ENTRY_TYPE_HTTP2) | |||
collectStats(entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this into the http2 namespace? I'm kind of -1 on having perf-hooks require something within http2 itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not following. The collectStats
method is in the internal/http2/util.js
file. It is used here because we are instrumenting the http2 performance entry object with the http2 specific details, which must be done within this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the code in perf_hooks is isolated from the rest of core. We are not loading fs, http, net etc to instrument them. Why do we need to load a part of http2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, ok, so move the collectStats
method in to perf_hooks to keep from having to require anything from http2... yeah, I can do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this for http2 while we don't for http or net?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither http
or net
currently output any performance metrics via the perf_hooks API. That's something that's on my lower priority todo list. This is there for http2 because we're using an aliased buffer to move those data values out to js instead of setting properties on the object from within the C++ code -- it's far more efficient to do it this way. Eventually, once other bits of code are instrumented with perf_hooks output, similar mechanisms will be added. For instance, I'm planning on doing something similar with dns lookups fairly soon.
Updated to address the feedback. PTAL |
Add an aliased buffer for session and stream statistics, add a few more metrics
c416358
to
e5ddf5b
Compare
Trying again with a possible fix for the seemingly unrelated failure: https://ci.nodejs.org/job/node-test-pull-request/12450/ |
I'm reasonably certain this is not a flaky test. I ran it on my local environment against master and it succeeded. I ran a test against this PR and it fails. |
yeah, except this PR doesn't touch that code at all, which is quite strange. The only thing I can think of is that there's some weird interaction with AliasedBuffer. |
I'm thinking it has something to do with some alignment issue caused by the new aliased buffers. Trying a different fix. |
1b0bdd8
to
fbdf3b2
Compare
It's not this PR directly. Just including |
perf_hooks is not used at all by the failing test |
It's indirectly required by Anyway, a simple reproduction on master is: 'use strict';
process.binding('http2');
const common = require('../common');
process.on('beforeExit', common.mustCall(() => {
setTimeout(common.mustNotCall(), 1).unref();
})); |
@apapirovski I can’t reproduce with that :/ And btw, this reminds me of 941c65b … |
fbdf3b2
to
89dfeb6
Compare
Yeah, that was my first thought too @addaleax but I couldn't find anything that was keeping the loop open. Trying something else... CI: https://ci.nodejs.org/job/node-test-pull-request/12453/ |
Ok, lazy loading the |
Yes, but that will have to wait until tomorrow :) |
I also cannot reproduce from master the way @apapirovski has. |
@addaleax @Fishrock123 I'm guessing you're both on Windows? I can reproduce on Linux & macOS. |
I am currently using macOS 10.12.6. |
I'm unable to duplicate on Ubuntu VM or Windows. There really should not be anything in the |
Scheduling a PerformanceGCCallback should not keep the loop alive but due to the recent switch to using the native SetImmediate method, it does. Go back to using uv_async_t and add a regression test. PR-URL: nodejs#18051 Fixes: nodejs#18047 Refs: nodejs#18020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Scheduling a PerformanceGCCallback should not keep the loop alive but due to the recent switch to using the native SetImmediate method, it does. Go back to using uv_async_t and add a regression test. PR-URL: nodejs#18051 Fixes: nodejs#18047 Refs: nodejs#18020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
New CI now that #18051 landed: https://ci.nodejs.org/job/node-test-pull-request/12469/ |
Scheduling a PerformanceGCCallback should not keep the loop alive but due to the recent switch to using the native SetImmediate method, it does. Go back to using uv_async_t and add a regression test. Backport-PR-URL: #18050 PR-URL: #18051 Fixes: #18047 Refs: #18020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This should be ready to go |
Add an aliased buffer for session and stream statistics, add a few more metrics PR-URL: #18020 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Landed in a02fcd2 |
Add an aliased buffer for session and stream statistics, add a few more metrics PR-URL: #18020 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Scheduling a PerformanceGCCallback should not keep the loop alive but due to the recent switch to using the native SetImmediate method, it does. Go back to using uv_async_t and add a regression test. Backport-PR-URL: #18050 PR-URL: #18051 Fixes: #18047 Refs: #18020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Add an aliased buffer for session and stream statistics, add a few more metrics PR-URL: #18020 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Add an aliased buffer for session and stream statistics, add a few more metrics PR-URL: nodejs#18020 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Scheduling a PerformanceGCCallback should not keep the loop alive but due to the recent switch to using the native SetImmediate method, it does. Go back to using uv_async_t and add a regression test. PR-URL: #18051 Fixes: #18047 Refs: #18020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Scheduling a PerformanceGCCallback should not keep the loop alive but due to the recent switch to using the native SetImmediate method, it does. Go back to using uv_async_t and add a regression test. PR-URL: #18051 Fixes: #18047 Refs: #18020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Scheduling a PerformanceGCCallback should not keep the loop alive but due to the recent switch to using the native SetImmediate method, it does. Go back to using uv_async_t and add a regression test. PR-URL: #18051 Fixes: #18047 Refs: #18020 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Add an aliased buffer for session and stream statistics, add a few more useful metrics
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
http2